/**
 * fabric三方Api
 */
import apiCommon from './api-common';
import { objHas } from '@/utils/util.js';

export default {
  getDataSourceList() {
    return window._UIDesingerAxios({
      method: 'get',
      url: '/api-manager/api/v1/flatten/apis?currPage=1&pageSize=999',
    });
  },

  /**
   * 获取 API编码
   * @param {string} datasourceCode 数据源编码code
   */
  getAPICodeList(datasourceCode) {
    return window._UIDesingerAxios({
      method: 'get',
      url: `/api-manager/api/v1/flatten/paths?apiBaseCode=${datasourceCode}`,
    }).then(res => {
      res.data.data = res.data.data.filter(n => {
        if (!objHas(n, 'status')) {
          return true;
        }
        if (n.status === '1') {
          return true;
        }
        return false;
      });
      return res;
    });
  },

  getMappingOptions(apiPathCode) {
    return window._UIDesingerAxios({
      method: 'get',
      url: `/api-manager/api/v1/flatten/pathDetail?apiPathCode=${apiPathCode}`,
    });
  },

  getChartData(params, data) {
    const _params = apiCommon.clearParams(params);
    const { actType, switchEnable } = data?.autoRefresh || {};
    return window._UIDesingerAxios({
      method: 'post',
      url: '/api-manager/api/v1/flatten/exchange',
      data: _params,
      headers: {
        'Content-Type': 'application/json',
      },
      isPolling: switchEnable && actType === 'pull',
    });
  },

};
